﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;

namespace Honestysoft.Financing.WebUI.Module.Audit.JSON
{
    /// <summary>
    /// GetProjectDocumentStatus 的摘要说明
    /// </summary>
    public class GetProjectDocumentStatus : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            //得到项目的最后一次作业表中记录的项目基本情况审批资料来给予新的收文
            string responseData = "";
            string sn = context.Request.Params["SN"];
            string code = context.Request.Params["Code"];
            string by = context.Request.Params["By"];
            Honestysoft.Financing.BusinessLogic.Project bll = new BusinessLogic.Project("");
            DataTable dt = null;
            if (by == "SN")
            {
                dt = bll.GetProjectDocumentStatusBySN(sn);
            }
            else
            {
                dt = bll.GetProjectDocumentStatusByCode(code);
            }
            if (dt == null || dt.Rows.Count == 0)
            {
                responseData = "-1";
            }
            else
            {
                if (dt.Rows.Count == 1)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("[");
                    sb.Append("{");
                    sb.AppendFormat("\"IsPD1\":\"{0}\",", Convert.ToBoolean( dt.Rows[0]["IsPD1"])==true ? "1" : "0");
                    sb.AppendFormat("\"IsPD2\":\"{0}\",", Convert.ToBoolean(dt.Rows[0]["IsPD2"]) == true ? "1" : "0");
                    sb.AppendFormat("\"IsPD3\":\"{0}\",", Convert.ToBoolean(dt.Rows[0]["IsPD3"]) == true ? "1" : "0");
                    sb.AppendFormat("\"IsPD4\":\"{0}\",", Convert.ToBoolean(dt.Rows[0]["IsPD4"]) == true ? "1" : "0");
                    sb.AppendFormat("\"IsPD5\":\"{0}\",", Convert.ToBoolean(dt.Rows[0]["IsPD5"]) == true ? "1" : "0");
                    sb.AppendFormat("\"IsPD6\":\"{0}\",", Convert.ToBoolean(dt.Rows[0]["IsPD6"]) == true ? "1" : "0");
                    sb.AppendFormat("\"IsPD7\":\"{0}\",", Convert.ToBoolean(dt.Rows[0]["IsPD7"]) == true ? "1" : "0");
                    sb.AppendFormat("\"IsPD8\":\"{0}\",", Convert.ToBoolean(dt.Rows[0]["IsPD8"]) == true ? "1" : "0");
                    sb.AppendFormat("\"IsPD9\":\"{0}\",", Convert.ToBoolean(dt.Rows[0]["IsPD9"]) == true ? "1" : "0");
                    sb.AppendFormat("\"IsPD10\":\"{0}\"", Convert.ToBoolean(dt.Rows[0]["IsPD10"]) == true ? "1" : "0");
                    sb.Append("}");
                    sb.Append("]");
                    responseData = sb.ToString();
                }
                else
                {
                    responseData = "0";
                }
            }
            context.Response.Write(responseData);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}